from visual import *

def printBox(lbox,rad):
    lx=lbox[0]
    ly=lbox[1]
    lz=lbox[2]
    scene2 = display(title='set Q',width=600, height=600, center=(0.5*lx,0.5*ly,0.5*lz), background=(0.95,0.95,0.95))
    L0 = scene.lights[0]
    L0.color = 0.9*vector(L0.color)
    scene2.lights = [L0]
    d = L0.direction
    L1 = distant_light(direction=(lx,0,0),       color=L0.color)
    rod = cylinder(pos=(-0.5*lx,-0.5*ly,-0.5*lz),axis=(lx,0,0), radius=rad, color = color.black)
    rod = cylinder(pos=(-0.5*lx,-0.5*ly,-0.5*lz),axis=(0,ly,0), radius=rad, color = color.black)
    rod = cylinder(pos=(-0.5*lx,-0.5*ly,-0.5*lz),axis=(0,0,lz), radius=rad, color = color.black)
    rod = cylinder(pos=(0.5*lx,-0.5*ly,-0.5*lz),axis=(0,ly,0), radius=rad, color = color.black)
    rod = cylinder(pos=(0.5*lx,-0.5*ly,-0.5*lz),axis=(0,0,lz), radius=rad, color = color.black)
    rod = cylinder(pos=(-0.5*lx,0.5*ly,-0.5*lz),axis=(0,0,lz), radius=rad, color = color.black)
    rod = cylinder(pos=(-0.5*lx,0.5*ly,-0.5*lz),axis=(lx,0,0), radius=rad, color = color.black)
    
    rod = cylinder(pos=(-0.5*lx,-0.5*ly,0.5*lz),axis=(lx,0,0), radius=rad, color = color.black)
    rod = cylinder(pos=(-0.5*lx,-0.5*ly,0.5*lz),axis=(0,ly,0), radius=rad, color = color.black)
    
    rod = cylinder(pos=(0.5*lx,0.5*ly,-0.5*lz),axis=(0,0,lz), radius=rad, color = color.black)
    rod = cylinder(pos=(0.5*lx,-0.5*ly,0.5*lz),axis=(0,ly,0), radius=rad, color = color.black)
    rod = cylinder(pos=(-0.5*lx,0.5*ly,0.5*lz),axis=(lx,0,0), radius=rad, color = color.black)

def showSystem(xpos,diameter):
    sistema=[]
    scene.background = color.gray(0.7)
    for i in range(len(diameter)):
        ball = sphere (pos=xpos[i], radius=diameter[i]*0.5, color = color.red ,material=materials.rough)
        #ball = sphere (pos=xpos[i], radius=10./18., color = color.red ,material=materials.rough)
        sistema.append(ball)
    return sistema

dir='/Users/jonk/Documents/xcode/chainsKlin/chainsKlin/'
name='tonto.dat'
[lx,ly,lz] = [100.0,100.0,100.0]
pos=[]
for line in file(dir+name):
    line=line.replace('\n','')
    val=line.split(' ')
    aux=[]
    for v in val:
        if v!='':
            aux.append(float(v))
    pos.append(aux)

diameter=[1]*len(pos)
printBox([lx,ly,lz],0.1)
showSystem(pos,diameter)